package com.zenithmind.coding.controller;

import com.zenithmind.common.result.Result;
import com.zenithmind.coding.service.LanguageSupportService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 编程语言支持控制器 - 遵循单一职责原则，专门处理编程语言支持相关功能
 * 
 * @author ZenithMind Team
 * @since 2025-01-09
 */
@Tag(name = "编程语言支持", description = "编程语言支持和配置相关接口")
@RestController
@RequestMapping("/api/zenithMind/v1/languages")
@RequiredArgsConstructor
public class LanguageSupportController {

    private final LanguageSupportService languageSupportService;

    @Operation(summary = "获取支持的编程语言", description = "获取平台支持的编程语言列表")
    @GetMapping
    public Result<String[]> getSupportedLanguages() {
        String[] languages = languageSupportService.getSupportedLanguages();
        return Result.success(languages);
    }

    @Operation(summary = "检查语言支持", description = "检查指定编程语言是否支持")
    @GetMapping("/{language}/supported")
    public Result<Boolean> isLanguageSupported(
            @Parameter(description = "编程语言") @PathVariable String language) {
        Boolean supported = languageSupportService.isLanguageSupported(language);
        return Result.success(supported);
    }

    @Operation(summary = "获取语言配置", description = "获取指定编程语言的配置信息")
    @GetMapping("/{language}/config")
    public Result<Object> getLanguageConfig(
            @Parameter(description = "编程语言") @PathVariable String language) {
        Object config = languageSupportService.getLanguageConfig(language);
        return Result.success(config);
    }

    @Operation(summary = "获取语言模板", description = "获取指定编程语言的代码模板")
    @GetMapping("/{language}/template")
    public Result<String> getLanguageTemplate(
            @Parameter(description = "编程语言") @PathVariable String language,
            @Parameter(description = "模板类型") @RequestParam(defaultValue = "basic") String templateType) {
        String template = languageSupportService.getLanguageTemplate(language, templateType);
        return Result.success(template);
    }

    @Operation(summary = "获取语言示例", description = "获取指定编程语言的示例代码")
    @GetMapping("/{language}/examples")
    public Result<Object> getLanguageExamples(
            @Parameter(description = "编程语言") @PathVariable String language) {
        Object examples = languageSupportService.getLanguageExamples(language);
        return Result.success(examples);
    }

    @Operation(summary = "获取语言文档", description = "获取指定编程语言的文档链接")
    @GetMapping("/{language}/documentation")
    public Result<Object> getLanguageDocumentation(
            @Parameter(description = "编程语言") @PathVariable String language) {
        Object documentation = languageSupportService.getLanguageDocumentation(language);
        return Result.success(documentation);
    }

    @Operation(summary = "获取语言版本", description = "获取指定编程语言的版本信息")
    @GetMapping("/{language}/version")
    public Result<String> getLanguageVersion(
            @Parameter(description = "编程语言") @PathVariable String language) {
        String version = languageSupportService.getLanguageVersion(language);
        return Result.success(version);
    }

    @Operation(summary = "获取语言特性", description = "获取指定编程语言支持的特性")
    @GetMapping("/{language}/features")
    public Result<Object> getLanguageFeatures(
            @Parameter(description = "编程语言") @PathVariable String language) {
        Object features = languageSupportService.getLanguageFeatures(language);
        return Result.success(features);
    }

    @Operation(summary = "获取语言限制", description = "获取指定编程语言的执行限制")
    @GetMapping("/{language}/limits")
    public Result<Object> getLanguageLimits(
            @Parameter(description = "编程语言") @PathVariable String language) {
        Object limits = languageSupportService.getLanguageLimits(language);
        return Result.success(limits);
    }

    @Operation(summary = "添加语言支持", description = "添加新的编程语言支持")
    @PostMapping
    public Result<Boolean> addLanguageSupport(
            @Parameter(description = "语言配置") @RequestBody Object languageConfig) {
        Boolean success = languageSupportService.addLanguageSupport(languageConfig);
        return Result.success(success);
    }

    @Operation(summary = "更新语言配置", description = "更新指定编程语言的配置")
    @PutMapping("/{language}")
    public Result<Boolean> updateLanguageConfig(
            @Parameter(description = "编程语言") @PathVariable String language,
            @Parameter(description = "语言配置") @RequestBody Object languageConfig) {
        Boolean success = languageSupportService.updateLanguageConfig(language, languageConfig);
        return Result.success(success);
    }

    @Operation(summary = "禁用语言支持", description = "禁用指定编程语言的支持")
    @PostMapping("/{language}/disable")
    public Result<Boolean> disableLanguageSupport(
            @Parameter(description = "编程语言") @PathVariable String language) {
        Boolean success = languageSupportService.disableLanguageSupport(language);
        return Result.success(success);
    }

    @Operation(summary = "启用语言支持", description = "启用指定编程语言的支持")
    @PostMapping("/{language}/enable")
    public Result<Boolean> enableLanguageSupport(
            @Parameter(description = "编程语言") @PathVariable String language) {
        Boolean success = languageSupportService.enableLanguageSupport(language);
        return Result.success(success);
    }
}
